#include<stdio.h>

int Mystrlen(const char*s)
{
    int count=0;
    while(*s!='\0')
    {
        s++;
        count++;
    }
    return count;
}

void Mystrcpy(char *dest,const char *src)
{
     while(*src!='\0')
     {
        *dest=*src;
        dest++;
        src++;
     }
     *dest='\0';
}

void Mystrcat(char *dest,const char *src)
{
    while(*dest!='\0')
    {
        dest++;
    }
    Mystrcpy(dest,src);
}

char*Mystrstr(char *s,const char *d)
{
    for(int i=0;s[i]!='\0';i++)
    {
        int flag=0;
        for(int j=0;d[j]!='\0';j++)
        {
            if(s[i+j]!=d[j])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            return s+i;
        }
    }
    return NULL;
}

char*Mystrtok(char*dest,const char*demil)
{
    static char*next=NULL;
    if(dest!=NULL)
    {
    char*target=Mystrstr(dest,demil);
    if(target==NULL)
        return dest;
    *target='\0';
    next=target+Mystrlen(demil);
    return dest;
     
    }
    else
    {
       if(next==NULL)
       {
        return NULL;
       }
        else
        {
           char*target=Mystrstr(next,demil);
           if(target==NULL)
           {
              char *returnValue=next;
              next=NULL;
              return returnValue;
            }
           *target='\0';
           char *returnValue=next;
           next=target+Mystrlen(demil);
           if(*next=='\0')
           {
            next=NULL;
           }
           return returnValue;
        }
    }
}

int Mystrcmp(const char *s1,const char*s2)
{
    while(*s1!='\0'&&*s2!='\0')
    {
        if(*s1!=*s2)
        {
            return *s1-*s2;
        }
        s1++;
        s2++;
    }
    return *s1-*s2;
}

int main()
{
    //char*s="aaa";
    //char*s2="abb";
    //printf("%d\n",Mystrcmp(s1,s2));
    char s[]="zhangsan,lisi,wangwu";
    //char s2[20]="hello";
    char *p=Mystrtok(s,",");
    while(p!=NULL)
    {
    printf("%s\n",p);
    p=Mystrtok(NULL,",");
    }
    
    //printf("%d\n",Mystrlen(s1));
    //char *p=Mystrstr(s,s2);
    //printf("%x %x\n",s,p);
    //Mystrcpy(s2,s);
    //char a[10]="fujieping";
    //char b[4]="jie";
    //Mystrcat(a,b);
    //printf("%s\n",a);
    return 0;
}    

